
/****** Object:  StoredProcedure [dbo].[SFDA_X_ProcessUserInfo_StaffFiles]    Script Date: 07/27/2013 18:19:16 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[SFDA_X_ProcessUserInfo_StaffFiles]
	@staffFilesID NVARCHAR(50)='', @userNo NVARCHAR(50)='', @userName NVARCHAR(50)='', @userDescription NVARCHAR(50)='', 
	@departmentNo NVARCHAR(50)='', @pwd NVARCHAR(50)='', @isCW NVARCHAR(50)='', @isJJ NVARCHAR(50)='', @databaseName NVARCHAR(50)=''
AS
SET NOCOUNT ON;

DECLARE @departmentId INT 
SELECT @departmentId = departmentFilesID FROM T_departmentFiles WHERE (departmentNo = @departmentNo)

DECLARE @iCount INT
SELECT @iCount = COUNT(userId) FROM userProfile WHERE (staffFilesID = @staffFilesID)
IF @iCount > 0
BEGIN
	UPDATE userProfile SET userName = @userName, userDescription = @userDescription, pwd = @pwd, departmentId = @departmentId, isCW = @isCW, isJJ = @isJJ WHERE staffFilesID = @staffFilesID
END
ELSE
BEGIN
	INSERT INTO userProfile(userNo, userName, userDescription, internal, orgId, departmentId, pwd, dataBaseName, staffFilesID, isCW, isJJ)
	VALUES(@userNo, @userName, @userDescription, 0, 0, @departmentId, @pwd, @dataBaseName, @staffFilesID, @isCW, @isJJ)
END

SELECT 'FETCH'


--SELECT * FROM T_departmentFiles
--SELECT * FROM USERPROFILE
GO

